﻿using AjaxControlToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

/// <summary>
/// Summary description for AutoComplete
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
 [System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService
{

    public AutoComplete()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [System.Web.Script.Services.ScriptMethod]
    [WebMethod]
    public static string[] SearchCities(string prefixText, int count)
    {
        using (POSEntities db = new POSEntities())
        {

            var cities = (from c in db.Cities where c.City_Name.Contains(prefixText) select c).ToArray();
            return cities.Select(c => AutoCompleteExtender.CreateAutoCompleteItem(c.City_Name, c.City_ID.ToString())).ToArray();
        }
    }

}
